package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.EssayCourseQuestionBank;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface EssayCourseQuestionBankRepository extends JpaRepository<EssayCourseQuestionBank, Integer>, JpaSpecificationExecutor {
    //根据id更新题库资源
    @Modifying
    @Transactional
    @Query(value = "update EssayCourseQuestionBank ecq set ecq.audio = ?1, ecq.questionAnalysisAudio = ?2, ecq.questionAnalysisImage = ?3, ecq.image = ?4 where ecq.id = ?5")
    void updateResourceById(String audio, String questionAnalysisAudio, String questionAnalysisImage, String image, Integer questionId);

    //根据id获取题目
    @Query(value = "select ecq from EssayCourseQuestionBank ecq where ecq.id = ?1")
    EssayCourseQuestionBank findQuestionBankById(Integer id);

    //根据id获取题目
    @Query(value = "select ecq from EssayCourseQuestionBank ecq where ecq.id = ?1")
    EssayCourseQuestionBank findQuestionBankByTaskId(Integer taskId);
}